package com.servlet;

import com.dao.EmployeeDao;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/delEmp")
public class EmpDelServlet extends HttpServlet {

    private EmployeeDao employeeDao = new EmployeeDao();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");

        String id = req.getParameter("id");
        int row = employeeDao.delete(Integer.parseInt(id));

        if (row>0){
            req.setAttribute("msg","宿舍删除成功");
        }else{
            req.setAttribute("msg","宿舍删除失败");
        }

        req.getRequestDispatcher("msg.jsp").forward(req,resp);



    }
}
